package com.jas.storage;

import java.lang.reflect.Type;
import java.util.ArrayList;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.jas.common.Event;

public class EventSerializer implements JsonSerializer<ArrayList<Event>> {

	//@author a0118677r
    @SuppressWarnings("rawtypes")
	@Override
    public JsonElement serialize(ArrayList<Event> listOfEvents, Type type,
            JsonSerializationContext context) {
        if (listOfEvents == null)
            return null;
        else {
            JsonArray jsonArray = new JsonArray();
            for (Event event : listOfEvents) {
                Class eventSubClass = event.getSubClass();
                jsonArray.add(context.serialize(event, eventSubClass));
            }
            return jsonArray;
        }
    }
}
